package com.kuyou.ddhm_tv.view;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.clj.fastble.data.BleDevice;
import com.kuyou.ddhm_tv.R;
import com.kuyou.ddhm_tv.adapter.BleDeviceAdapter;
import com.kuyou.publiclibrary.utils.ScreenUtils;

import java.util.ArrayList;
import java.util.List;

public class BleDeviceDialog extends AlertDialog {
    public  BleDeviceAdapter  ad ;
    public RecyclerView recyclerView;
    private OnDialogSelectCallback onDialogSelectCallback;

    public BleDeviceDialog(Context context) {
        super(context);
        init(new ArrayList<>());
    }

    public void init(List<BleDevice> list){
        ad = new BleDeviceAdapter(getContext());

        ad.setList(list);
        ad.setOnItemClick((device) -> {
            if (onDialogSelectCallback != null) {
                onDialogSelectCallback.onSelectItem(device);
            }
        });

    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_select_item);

        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        recyclerView.setAdapter(ad);
    }

    public void addItem(BleDevice bleDevice){
        ad.addItem(bleDevice);
        ad.notifyDataSetChanged();
    }
    public void remove(){
        ad.removeList();

    }


    public void setOnDialogSelectCallback(OnDialogSelectCallback onDialogSelectCallback) {
        this.onDialogSelectCallback = onDialogSelectCallback;
    }

    public interface OnDialogSelectCallback {

        void onSelectItem(BleDevice bleDevice);
    }

}
